package com.skyeyes.service.impl;

import com.skyeyes.constant.MessageConstant;
import com.skyeyes.entity.UserBean;
import com.skyeyes.exception.AccountNotFoundException;
import com.skyeyes.exception.PasswordErrorException;
import com.skyeyes.mapper.LoginMapper;
import com.skyeyes.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;


    @Override
    public UserBean login(String phone, String password) {

        UserBean userBean=loginMapper.getByUsername(phone);
        if(userBean==null){
            //账号不存在
            throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND);

        }
        if (!password.equals(userBean.getPassword())) {
            //密码错误
            throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
        }
        return userBean;
    }
}
